package com.qen.encrypt.configuration;

import com.qen.encrypt.filter.DecryptRequestFilter;
import com.qen.encrypt.properties.EncryptMapConfig;
import com.qen.encrypt.properties.EncryptProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.util.UrlPathHelper;

/**
 * 自动配置类
 */
@Configuration
@EnableConfigurationProperties({EncryptProperties.class})
public class EncryptAutoConfiguration {

    private EncryptProperties encryptProperties;

    public EncryptAutoConfiguration(@Qualifier("encryptProperties") EncryptProperties encryptProperties) {
        this.encryptProperties = encryptProperties;
    }

    @Bean
    public DecryptRequestFilter decryptRequestFilter(@Qualifier("encryptMapConfig") EncryptMapConfig encryptMapConfig) {
        return new DecryptRequestFilter(encryptMapConfig, new UrlPathHelper());
    }

    @Bean
    public EncryptMapConfig encryptMapConfig() {
        return new EncryptMapConfig(encryptProperties);
    }

}
